package com.useeinfo.oa.modules.logger.entity;

import com.alibaba.fastjson.JSONObject;
import com.useeinfo.framework.extend.entity.SuperClassEntity;
import com.useeinfo.framework.sugar.tools.StringConverters;
import com.useeinfo.oa.modules.logger.enums.LogTypeEnum;
import javax.persistence.*;
import java.util.Optional;

/**
 * @auther: bin.liu
 * @Date: 2018/12/25 9:43
 * @Description:  资料操作日志表
 */
@Entity
@Table(name = "log_facility_data")
public class FacilityDataLog extends SuperClassEntity<FacilityDataLog> {

    /**
     * 资料id
     */
    private Long facilityDataId;

    /**
     * 资料名称
     */
    private String facilityDataName;
    /**
     * 内容
     */
    private String content;
    /**
     * 操作人
     */
    private String userName;
    /**
     * 操作人ID
     */
    private Long userId;
    /**
     * 操作人ip
     */
    private String userIp;
    /**
     * 企业id
     */
    private Long enterpriseId;
    /**
     * 操作类型
     */
    @Enumerated(value = EnumType.STRING)
    @Column(name = "log_type")
    private LogTypeEnum logTypeEnum;


    public Long getFacilityDataId() {
        return facilityDataId;
    }

    public void setFacilityDataId(Long facilityDataId) {
        this.facilityDataId = facilityDataId;
    }

    public String getFacilityDataName() {
        return facilityDataName;
    }

    public void setFacilityDataName(String facilityDataName) {
        this.facilityDataName = facilityDataName;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public String getUserIp() {
        return userIp;
    }

    public void setUserIp(String userIp) {
        this.userIp = userIp;
    }

    public Long getEnterpriseId() {
        return enterpriseId;
    }

    public void setEnterpriseId(Long enterpriseId) {
        this.enterpriseId = enterpriseId;
    }

    public LogTypeEnum getLogTypeEnum() {
        return logTypeEnum;
    }

    public void setLogTypeEnum(LogTypeEnum logTypeEnum) {
        this.logTypeEnum = logTypeEnum;
    }

    @Override
    public JSONObject toJSONObject(){
        JSONObject jsonObject = super.toJSONObject();
        jsonObject.put("facilityDataId", StringConverters.null2String(getFacilityDataId()));
        jsonObject.put("facilityDataName", StringConverters.null2String(getFacilityDataName()));
        jsonObject.put("content", StringConverters.null2String(getContent()));
        jsonObject.put("userName", StringConverters.null2String(getUserName()));
        jsonObject.put("userIp", StringConverters.null2String(getUserIp()));
        jsonObject.put("logTypeEnum", Optional.ofNullable(getLogTypeEnum()).map(LogTypeEnum::getName).orElse(""));

        return jsonObject;
    }
}
